import students.dao.ScoreManage;
import students.dao.UserManage;
import students.dao.clazzManage;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import students.pojo.scores;
import students.pojo.users;

public class test {

    @Test
    public void test() {

        xsdl();


    }

    public void jsdl() {
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("context.xml");

        users users = (users) context.getBean("users");
        UserManage usersManage = (UserManage) context.getBean("UserManage");
        scores scores = (scores) context.getBean("scores");
        ScoreManage scoreManage = (ScoreManage)context.getBean("ScoreManage");
        clazzManage clazzManage= (clazzManage)context.getBean("clazzManage");

        users.setNumber("123");
        users.setPassword("123");
        users.setIdentity("教师");

        if(usersManage.login(users)){
            System.out.println(users.getIdentity()+"登录成功");

//            System.out.println("插入成绩");
//            scores.setNumber("123");
//            scores.setChinsese(100);
//            scores.setEnglish(100);
//            scores.setMath(100);
//            scoreManage.add(scores);
//            System.out.println("查询所有学生成绩");
//            scoreManage.getScoreAll();

            System.out.println("更新123的数学成绩");
            scoreManage.update("123","Math",59);
            System.out.println("查询所有成绩");
            scoreManage.getScoreAll();

        }else {
            System.out.println("登录失败");
        }

    }

    public void xsdl(){
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("context.xml");

        users users = (users) context.getBean("users");
        UserManage usersManage = (UserManage) context.getBean("UserManage");
        scores scores = (scores) context.getBean("scores");
        ScoreManage scoreManage = (ScoreManage)context.getBean("ScoreManage");
        clazzManage clazzManage= (clazzManage)context.getBean("clazzManage");

        users.setNumber("123");
        users.setPassword("123");
        users.setIdentity("学生");

        if(usersManage.login(users)){
            System.out.println(users.getIdentity()+"登录成功");
            System.out.println("查询该学生成绩");
            scoreManage.getScore("123");
            System.out.println("查询待选课记录");
            clazzManage.query();

            try {
                System.out.println("选课");
            clazzManage.select("123","moive");
            }catch (RuntimeException e){
                System.out.println("选课失败");
                System.out.println("回滚");
            }
            finally {
                System.out.println("执行选课操作后，查询待选课程记录");
                clazzManage.query();
            }
        }else {
            System.out.println("登录失败");
            //关闭容器
            context.close();
        }
    }
}
